package classes;

import exceptions.RepositoryException;
import business.MemberBusiness;


public class Classroom extends Storable implements Tableble
{
	private String			name;
	private String			magazine;
	private int				titularTeacherId;
	private int				auxiliarTeacherId;
	
	private MemberBusiness	memberBusiness;		

	public Classroom( String name, String magazine, int titularTeacherId, int auxiliarTeacherId )
	{
		this.setName( name );
		this.setMagazine( magazine );
		this.setTitularTeacherId( titularTeacherId );
		this.setAuxiliarTeacherId( auxiliarTeacherId );
		
		try
		{
			memberBusiness = new MemberBusiness();
		}
		catch ( RepositoryException e )	{}
	}

	public int getAuxiliarTeacherId()
	{
		return auxiliarTeacherId;
	}

	public String getName()
	{
		return name;
	}

	public String getMagazine()
	{
		return magazine;
	}

	public int getTitularTeacherId()
	{
		return titularTeacherId;
	}
	
	public boolean equals( Object object )
	{
		boolean ret;
		
		ret = object instanceof Classroom && ( ( Classroom ) object ).getId() == this.getId();
		
		return ret;
	}

	public void setAuxiliarTeacherId( int auxiliarTeacherId )
	{
		this.auxiliarTeacherId = auxiliarTeacherId;
	}

	public void setName( String name )
	{
		this.name = name;
	}

	public void setMagazine( String revista )
	{
		this.magazine = revista;
	}

	public void setTitularTeacherId( int titularTeacherId )
	{
		this.titularTeacherId = titularTeacherId;
	}
	
	public String toString()
	{
		String ret;

		ret = this.getName();

		return ret;
	}

	@Override
	public String[] getHead()
	{
		String[] ret;
		
		ret = new String[] { "Id", "Nome", "Revista", "Titular", "Auxiliar" };
		
		return ret;
	}

	@Override
	public Object[] getRow()
	{
		Object[] ret;
		
		Member titular = null;
		Member auxiliar = null;
		try
		{
			titular = memberBusiness.get( this.titularTeacherId );
			auxiliar = memberBusiness.get( this.auxiliarTeacherId );
		}
		catch ( RepositoryException e ) {}
		
		ret = new Object[] { String.valueOf( this.getId() ), this.name, this.magazine, titular, auxiliar };
		
		return ret;
	}
}
